/*
 * seq_stack.c
 *
 *  Created on: 2020��9��22��
 *      Author: Administrator
 */

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "../../include/stack/seq_stack.h"

void init_seqstack(SeqStack* stack) {

	stack->top = -1;
}

bool is_empty_seqstack(SeqStack* stack) {

	return stack->top == -1? true : false;
}

bool is_full_seqstack(SeqStack* stack) {

	return stack->top == STACK_SIZE - 1? true : false;
}

bool push_seqstack(SeqStack* stack, ElemType value) {

	if (is_full_seqstack(stack)) return false;
	// ���Ԫ��
	stack->top++;
	stack->elem[stack->top] = value;
	return true;
}

ElemType pop_seqstack(SeqStack* stack) {

	if (is_empty_seqstack(stack)) return ERROR;

	ElemType temp = stack->elem[stack->top];
	stack->top--;
	return temp;
}

ElemType peek_seqstack(SeqStack* stack) {

	if (is_empty_seqstack(stack)) return ERROR;

	ElemType top = stack->elem[stack->top];
	return top;
}

void print_seqstack(SeqStack* stack) {

	int temp = stack->top;
	if (is_empty_seqstack(stack)) return;
	while (temp != -1) {
		printf("%d ", stack->elem[temp]);
		temp--;
	}
	printf("\n");
}
